<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ page import="com.kms.model.*" %>
<%@ page import="com.kms.util.*" %>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";

List<MGroup> listmg = new ArrayList<MGroup>();
if(request.getAttribute("listmgroup")!=null){
	listmg = (List<MGroup>)request.getAttribute("listmgroup");
}

MSyspara msapp=new  MSyspara();
MSyspara msdb = new MSyspara() ;
List<Map>  listsys = new ArrayList<Map>();
if(request.getAttribute("listmgroup")!=null){
	for(MGroup mg:listmg){
		Map<String,Object>	mapv = new HashMap<String,Object>();
		mapv.put("mgroup",mg);
		if(mg.getListsyspara()!=null){
			for(int j=0;j<mg.getListsyspara().size();j++){
				MSyspara ms = mg.getListsyspara().get(j);
				if("APP".equals(ms.getDatatype())){
					msapp = ms;
					mapv.put("sysapp",ms);
				}else{
					msdb = ms;
					mapv.put("sysdb",ms);
				}	
			}
		}
		listsys.add(mapv);
	}
}



Map mapv = new HashMap();
if(request.getAttribute("infomap")!=null){
	mapv=(Map)request.getAttribute("infomap");
	System.out.println(mapv);
}

%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"><head>
<title>JBoss Management Console - Server Information</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<link rel="StyleSheet" href="<%=basePath %>css/jboss.css" type="text/css">
</head>
<body>
<!-- header begin -->
	<img src="<%=basePath %>img/logo.gif" alt="JBoss" id="logo" height="105" width="226">
	<div id="header">&nbsp;</div>
	<div id="navigation_bar">
	</div>
<!-- header end -->
<hr class="hide">
<h3 align="center">Server Info</h3>
<hr class="hide">

<table width="524" height="49" border="1" cellpadding="1" cellspacing="1" align="center">

<%

for(int i=0;i<listsys.size();){
	MSyspara mssysapp = new MSyspara();
	MSyspara mssysdb = new MSyspara();
	MSyspara mssysapp2 = new MSyspara();
	MSyspara mssysdb2 = new MSyspara();
	MGroup mgroup = new MGroup();
	MGroup mgroup2 = new MGroup();
	Map map = listsys.get(i);
	Map map2 = (i+1)>=listsys.size()?null:listsys.get(i+1);
	if(map!=null ){
		if(map.get("mgroup")!=null){
			mgroup = (MGroup)map.get("mgroup");
		}
		if(map.get("sysapp")!=null ){
			mssysapp = (MSyspara)map.get("sysapp");
		}
		if(map.get("sysdb")!=null ){
			mssysdb = (MSyspara)map.get("sysdb");
		}
	}
	
	if(map2!=null ){
		if(map2.get("mgroup")!=null){
			mgroup2 = (MGroup)map2.get("mgroup");
		}
		if(map2.get("sysapp")!=null ){
			mssysapp2 = (MSyspara)map2.get("sysapp");
		}
		if(map2.get("sysdb")!=null ){
			mssysdb2 = (MSyspara)map2.get("sysdb");
		}
	}
	
	%>
  <tr>
    <td width="51" rowspan="2"><%=(mgroup).getName() %></td>
    <td width="72" bgcolor="#CCCCCC">
    	<a href="<%=basePath %>systeminfo?id=<%=(mssysapp).getId() %> " >
    		<%=(mssysapp).getDatatype() %>
    	</a>
    </td>
    <td width="121">
    	<a href="<%=basePath %>systeminfo?id=<%=(mssysapp).getId() %> " >
    		<%=(mssysapp).getOsip() %>
    	</a>
    </td>
<%
    if(map2!=null){
    	%>
		    <td width="51" rowspan="2">
				    <%=(mgroup2).getName() %>
			</td>
		    <td width="60" bgcolor="#CCCCCC">
			    <a href="<%=basePath %>systeminfo?id=<%=(mssysapp2).getId() %> " >
			    	<%=(mssysapp2).getDatatype() %>
			    </a>
		    </td>
		    <td width="136">
		    	<a href="<%=basePath %>systeminfo?id=<%=(mssysapp2).getId() %> " >
		    		<%=(mssysapp2).getOsip() %>
		    	</a>
		    </td>
    	<%
    }
%>

  </tr>
  <tr>
    <td bgcolor="#CCCCCC">
    	<a href="<%=basePath %>systeminfo?id=<%=(mssysdb).getId() %> " >
    		<%=(mssysdb).getDatatype() %>
    	</a>
    </td>
    <td>
    	<a href="<%=basePath %>systeminfo?id=<%=(mssysdb).getId() %> " >
    		<%=(mssysdb).getOsip() %>
    	</a>
    </td>
<%
    if(map2!=null){
    	%>
			<td bgcolor="#CCCCCC">
	    	<a href="<%=basePath %>systeminfo?id=<%=(mssysdb2).getId() %> " >
	    		<%=(mssysdb2).getDatatype() %>
	    	</a>
		    </td>
		    <td>
		    	<a href="<%=basePath %>systeminfo?id=<%=(mssysdb2).getId() %> " >
		    		<%=(mssysdb2).getOsip() %>
		    	</a>
		    </td>
    	<%
    }
%>
  </tr>
	<%
	i=i+2;}
%>
</table> 
	<center>
<div id="content">
		<div class="content_block" style="width: 100%; height: 247">
			<h3>TBSMonitor&#8482; Application Server</h3>
					<p>&nbsp;</p>
				<table>
                 <tbody>
                 <%
	                 Iterator it = mapv.keySet().iterator();
                 	while(it.hasNext()){
	                 String infotype = it.next()+"";
	                 	%>
	                 	 <tr>
		                    <td >
		                    <h4><%=infotype %></h4>
		                    	<%
		                    		String contends = mapv.get(infotype)+"";
					                 for(String line:contends.split("\n")){
					                	  out.println(line+"<br>");
					                 }
		                    	%>
		                    </td>
	                    </tr>
	                 	<%
                 	}
                 %>
            </tbody>
            </table>
		</div>
		<div class="spacer"><hr></div>
	</div>
</center>
<!-- content end -->
<!-- content end -->

<hr class="hide">
<!-- footer begin -->
	<div id="footer">
		<div id="credits">TBSMonitor&#8482; Management Console</div>
		<div id="footer_bar">&nbsp;</div>
	</div>
<!-- footer end -->

</table>
</body>

</html>
